<template>
  <div class="personal">
    <div class="personalData">
      <p class="actived" v-show="!isedit">个人资料</p>
      <p class="actived" v-show="isedit">编辑资料</p>
    </div>
    <div class="userData" v-if="!isedit">
        <!-- 头像,昵称 ,真实姓名,性别 -->
      <div>
        <div class="contentleft">头像:</div>
        <div class="contentright touxiang">
          <div>
            <img :src="head_portrait" alt="">
          </div>
        </div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>昵称:
        </div>
        <div class="contentright">
          {{nickname}}
        </div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>真实姓名:
        </div>
        <div class="contentright smallsize">{{nickname}} 未实名认证</div>
      </div>
      <div>
        <div class="contentleft">性别:</div>
        <div class="contentright smallsize">{{radio=='2'?'女':'男'}}</div>
      </div>
        <!-- 手机号,邮箱,出生日期 -->
      <div>
        <div class="contentleft">手机号:</div>
        <div class="contentright smallsize">{{phone}}</div>
      </div>
      <div>
        <div class="contentleft">邮箱:</div>
        <div class="contentright smallsize">{{email}}</div>
      </div>
      <div>
        <div class="contentleft">出生日期:</div>
        <div class="contentright smallsize">{{birthday}}</div>
      </div>
      <!-- QQ号码,微信号码 -->
      <div>
        <div class="contentleft">QQ号码:</div>
        <div class="contentright smallsize">{{qqnumber}}</div>
      </div>
      <div>
        <div class="contentleft">微信号:</div>
        <div class="contentright smallsize">{{weixinnumber}}</div>
      </div>
      <div class="footer">
        <el-button type="primary" @click="editData" style="marginLeft:200px">编辑资料</el-button>
      </div>
    </div>
    <div class="personalDataContent" v-if="isedit">
      <!-- 头像,昵称 ,真实姓名,性别 -->
      <div>
        <div class="contentleft">头像:</div>
        <div class="contentright touxiang">
          <div>
            <el-upload
              class="avatar-uploader"
              action="http://39.108.122.107:1111/api/uploadImg"
              :headers="{'Authorization':'Bearer'+access_token}"
              :data="{upload_type:'head_portrait'}"
              :show-file-list="false"
              name="image"
              :on-success="handleAvatarSuccess"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon">点击上传</i>
            </el-upload>
          </div>
          <div class="uploaderp">支持大小不超过2M的jps,png图片</div>
        </div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>昵称:
        </div>
        <div class="contentright">
          <el-input v-model="nickname" placeholder="请输入昵称"></el-input>
        </div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>真实姓名:
        </div>
        <div class="contentright smallsize">{{nickname}} 未实名认证</div>
      </div>
      <div>
        <div class="contentleft">性别:</div>
        <div class="contentright smallsize">
          <template>
            <el-radio v-model="radio" label="1">男</el-radio>
            <el-radio v-model="radio" label="2">女</el-radio>
          </template>
        </div>
      </div>
      <!-- 手机号,邮箱,出生日期 -->
      <div>
        <div class="contentleft">
          <span class="red">*</span>手机号:
        </div>
        <div class="contentright smallsize">{{phone}} 修改</div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>邮箱:
        </div>
        <div class="contentright smallsize">164654465@qq.com 修改</div>
      </div>
      <div>
        <div class="contentleft">出生日期:</div>
        <div class="contentright smallsize">
          <el-input v-model="birthday" placeholder="请选择出生日期"></el-input>
        </div>
      </div>
      <!-- QQ号码,微信号码,验证码 -->
      <div>
        <div class="contentleft">QQ号码:</div>
        <div class="contentright smallsize">
          <el-input v-model="qqnumber" placeholder="请设置QQ号码"></el-input>
        </div>
      </div>
      <div>
        <div class="contentleft">微信号:</div>
        <div class="contentright smallsize">
          <el-input v-model="weixinnumber" placeholder="请设置微信号"></el-input>
        </div>
      </div>
      <div>
        <div class="contentleft">
          <span class="red">*</span>验证码:
        </div>
        <div class="contentright smallsize">
          <el-input v-model="checkcode" placeholder="请输入验证码"></el-input>
        </div>
      </div>
      <div class="footer">
        <el-button type="primary" style="margin:0 71px 0 400px" @click="overedit">编辑完成</el-button>
        <span style="marginTop:10px" >重置</span>
      </div>
    </div>
  </div>
</template>

<script>
import {gettoken} from '@@/assets/commen.js'

export default {
  layout: "user",
  data() {
    return {
      isedit: false,
      imageUrl: "",
      nickname:'',
      radio: "",
      email:'',
      birthday: "",
      qqnumber: "",
      phone:'',
      weixinnumber: "",
      checkcode: "",
      access_token: '',
      header_img:'https://zhong-zhi-chuan-mei.oss-cn-beijing.aliyuncs.com/',
      head_portrait:'',
    };
  },
  // async asyncData() {
  //   gettoken()
  //   access_token = localStorage.getItem('access_token')
  //    let {data} = await this.$axios.post('/me',{},{headers:{'Authorization':'Bearer '+access_token}})
  //    return {
  //      nickname:data.nickname,
  //    }
  // },
  mounted() {
    gettoken().then(val =>{
      this.access_token = val
      this.$axios.post('/me',{},{headers:{'Authorization':'Bearer'+this.access_token}}).then(res=>{
        this.nickname = res.data.data.nickname
        this.birthday = res.data.data.birth
        this.qqnumber = res.data.data.qq_ID
        this.weixinnumber = res.data.data.weixin_ID
        this.email = res.data.data.email
        this.radio = res.data.data.sex
        this.phone = res.data.data.phone
        this.head_portrait = this.header_img+res.data.data.head_portrait
      }).catch(err=>{
        console.log(err.response)
      })
      })
  },
  methods: {
    overedit(){                 //编辑完成按钮
      gettoken().then(val=>{
        this.access_token = val
        this.$axios.post('/saveInfo',{
          head_portrait:'images/head_portrait/9Qx34Jjhb9pbm3yFEJZZPLz3KrJ5Ob.jpeg',
          nickname:this.nickname,
          sex:this.radio,
          birth:this.birthday,
          qq_ID:this.qqnumber,
          weixin_ID:this.weixinnumber,
          imgCode:'2133',
          imgToken:'1423'
        },{headers:{'Authorization':'Bearer'+this.access_token}})
      })
    },
    editData() {
      this.isedit = true;
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
  
  }
};
</script>

<style scoped>
/* 上传框------------------------------------------ */
.el-icon-plus:before {
  color: transparent;
  margin-left: -10px;
}
.avatar-uploader {
  border: 1px solid rgba(210, 210, 210, 1);
  border-radius: 50%;
  background: rgba(248, 248, 248, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 14px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
/* 上传框end--------------------------------------------- */
.touxiang {
  position: relative;
  left: 40px;
}
.touxiang div{
  width: 98px;
  height: 98px;
  overflow: hidden;
}
.touxiang div img{
  width: 100%;
  height: 100%;
}
.uploaderp {
  width: 116px;
  height: 31px;
  font-size: 12px;
  font-family: MicrosoftYaHei;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  line-height: 18px;
  position: absolute;
  left: 130px;
  top: 25px;
}
.personal {
  background: #fff;
}
.personalData {
  height: 55px;
  border-bottom: 1px #d2d2d2 solid;
}
.personalData p {
  font-size: 16px;
  display: inline-block;
  line-height: 53px;
  margin-left: 30px;
  border-bottom: 2px #5141ed solid;
}
.personalDataContent,
.userData {
  padding-bottom: 50px;
}
.personalDataContent > div {
  display: flex;
  margin-top: 30px;
}
.userData > div {
  display: flex;
  margin-top: 15px;
}
.personalDataContent div .contentleft,
.userData div .contentleft {
  display: flex;
  width: 196px;
  margin-right: 19px;
  justify-content: flex-end;
  position: relative;
}
.red {
  color: red;
}
.contentright.smallsize {
  font-size: 14px;
}
.el-button--primary {
  background-color: #5141ed;
}
.active{
    border-bottom: 2px #5141ED solid;
    position: relative;
}
.active::before{
    content: '';
    border: 5px transparent solid;
    border-bottom: 5px #5141ED solid;
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-3px)
}
</style>
